﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Aribaccio.Custom
{
    /// <summary>
    /// 日期字符串转换器【yyyy-MM-dd HH:mm:ss】
    /// </summary>
    public class DateTimeConverter : IValueConverter
    {
        /// <summary>
        /// 日期转字符串
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is DateTime dateTime)
            {
                return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
            }
            return value;
        }
        /// <summary>
        /// 字符串转日期
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 对于只绑定到视图的转换器，通常不需要实现 ConvertBack 方法
            return value;
        }
    }
}
